package com.yhsimon.realm.member.controller;

import com.yhsimon.realm.member.entity.article.CommentEntity;
import com.yhsimon.realm.member.service.CommentService;
import com.yhsimon.realm.member.utils.R;
import com.yhsimon.realm.member.vo.article.CommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/member/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/saveComment")
    public R saveComment(@RequestBody CommentEntity commentEntity) {
        if (commentService.saveComment(commentEntity)) {
            return R.ok("评论成功");
        } else {
            return R.error("评论失败");
        }
    }

    @GetMapping("/listCommentByArticleId")
    public R listCommentByArticleId(@RequestParam(name = "articleId") String articleId,@RequestParam(name = "userId") String userId) {
        List<CommentVo> commentVoList = commentService.listCommentByArticleId(Long.parseLong(articleId), userId);
        return R.ok().put("data", commentVoList);
    }


    /**
     * 点赞评论
     */
    @GetMapping("/likeComment")
    public R likeComment(@RequestParam(name = "id") String id, @RequestParam(name = "userId") String userId) {
        commentService.likeComment(id, userId);
        return R.ok();
    }

}
